/**
 * 预览图片
 * @param {*} event 
 */
const previewImage = function (event) {
    let url = event.target.id;
    wx.previewImage({
        current: '',
        urls: [url]
    })
}
/**
 * 预览多张图片
 * @param {*} event 
 */
const previewMoreImage = function (event) {
    let images = event.currentTarget.dataset.obj.map(item => {
        return item;
    });
    let url = event.target.id;
    wx.previewImage({
        current: url,
        urls: images
    })
}
/**
 * 将微信小程序的头像显示为高清
 * @param {*} event 
 */
const previewWeChatAvatarUrlImage = function (event) {
    let url = event.target.id;
    let baseUrl = headimgHD(url);
    wx.previewImage({
        current: '',
        urls: [baseUrl]
    })
}
/**
 * 将微信头像URL返回为高清
 * @param {*} imageUrl 
 */
const headimgHD = function (imageUrl) {
    imageUrl = imageUrl.split('/'); //把头像的路径切成数组
    //把大小数值为 46 || 64 || 96 || 132 的转换为0
    if (
        imageUrl[imageUrl.length - 1] &&
        (imageUrl[imageUrl.length - 1] == 46 ||
            imageUrl[imageUrl.length - 1] == 64 ||
            imageUrl[imageUrl.length - 1] == 96 ||
            imageUrl[imageUrl.length - 1] == 132)
    ) {
        imageUrl[imageUrl.length - 1] = 0;
    }
    imageUrl = imageUrl.join('/'); //重新拼接为字符串
    return imageUrl;
}
module.exports = {
    previewImage,
    previewMoreImage,
    previewWeChatAvatarUrlImage
}

